package com.dearbinge.data.service.impl.shopgenre;

import com.dearbinge.data.api.shogenre.ShopGenreService;
import com.dearbinge.data.dao.shopgenre.ShopGenreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service(value = "shopGenreService")
public class ShopGenreServiceImpl implements ShopGenreService {

    @Autowired
    private ShopGenreMapper shopGenreMapper;

    @Override
    public List<Map> getIndexGenre() {
        List<Map> indexGenreList = shopGenreMapper.getIndexGenre();
        return indexGenreList;
    }

    @Override
    public List<Map> getShopGenre(Integer parentId) {
        if(parentId == 0 ){
            //一级分类加上二级分类前四个拼接成字符串
            List<Map> parentList = shopGenreMapper.getShopGenre(parentId);
            for(int index = 0;index < parentList.size();index++){
                parentId = Integer.valueOf(parentList.get(index).get("id").toString());
                List<Map> genreLevel2 = shopGenreMapper.getShopGenre(parentId);
                StringBuilder  genrename = new StringBuilder ();
                for(int i = 0;i < genreLevel2.size();i++){
                    if(i ==0){
                        genrename.append(genreLevel2.get(i).get("name").toString());
                    }else if(i<4){
                        genrename.append("、"+genreLevel2.get(i).get("name").toString());
                    }
                }
                parentList.get(index).put("genreLeve2",genrename);
            }
            return parentList;
        }else{
            return shopGenreMapper.getShopGenre(parentId);
        }

    }
}
